SetAxisCamSwitch

使用軸位置來控制觸發數位輸出的開關,當軸達到特定的位置,開關即開啟或關閉,而開關可受軸的向前或向厚運動控制。

語法

KsCommandStatus SetAxisCamSwitch(
     int Index,
     int SwitchLength,
     McCamSwitch* Switches,
     int TrackLength,
     McOutput* Outputs,
     McTrack* Tracks,
     DWORD EnableMask,
     McSource ValueSource
);

參數

Index [in]:軸索引。索引以零為起點;別名將影響此參數。

SwitchLength [in]:在開關陣列的開關數量,每一軌道最多可有八個開關。

Switches [in]:控制開關動作,軌道數量必須依照順序排列。請見 McCamSwitch 結構。

TrackLength [in]:軌道陣列中的軌道數量,輸出與軌道的長度必須一致。例如,有兩個輸出就必須有兩個軌道,最多可有 32 個軌道。

Outputs [in]:選擇對應軌道所控制的數位輸出。請見 McOutput 結構。

Tracks [in]:將補償時間和遲滯添加到軌道上的開關,TrackNumber 定義在 Switches 中。請見 McTrack 結構。

EnableMask [in]:啟用不同軌道,此參數為 BOOL 32 位元,當 BOOL 值設為一時將啟動軌道陣列中的相應軌道。

ValueSource [in]:定義軸值的來源,例如:位置。請見 McSource 類型。

回傳值

返回 KsCommandStatus 結構。

備註

McCamSwitch 結構內的元素

B/E 參數 類型 說明
B TrackNumber INT 軌道索引,以零為起點。
B FirstOnPosition [使用者單位] LREAL 開關開啟的位置。
B LastOnPosition [使用者單位] LREAL 開關關閉的位置。
E AxisDirection INT

軸方向,預設值為零。若選擇一或二,開關僅在當軸在指定方向移動時有效。

正負:0;正方向: 1;負方向: 2。

E CamSwitchMode INT

凸輪開關由軸的位置或時間控制,預設值為零。若選擇位置 (position),需設定 FirstOnPosition LastOnPosition;若選擇時間 (Time),需設定 FirstOnPosition Duration

位置 (position): 0,時間 (Time):1。

E Duration TIME 開關開啟的時間,此功能在 CamSwitchMode 為 Time 時可用,每秒為一單位。

 

McTrack 結構內的元素

B/E 參數 類型 說明
E OnCompensation TIME 在每個軌道的切換點之前或後打開開關(上升邊緣)的時間長度。 若值為正,則開啟將延遲;若值為負,則將提前開啟。
E OffCompensation TIME 在每個軌道的切換點之前或後關閉開關(下降邊緣)的時間長度。若值為正,則關閉將延遲;若值為負,則將提前關閉。
E Hysteresis [unit] LREAL 在軸離開該區域之前,從開關未打開或未關閉的切換點(正向和負向)的距離。 此可避免在開關點附近頻繁切換。

 

此凸輪定義具有起點與終點,如此使用者可定義每一個凸輪的 FirstOnPositionLastOnPosition(或時間),此功能或功能塊類似機械凸輪,但具有額外的優點,您可為輸出設置一個特定時間,並設定時間補償和遲滯。

CamSwitchMode:可為位置或時間。

Duration:時長,凸輪開啟的輸出時長,時間補償 (OnCompensation OffCompensation) 可為正或負值,負值表示輸出在開關位置到達前即變更。

Hysteresis:此參數可避免軸在切換點附近及實際位置在切換位置附近抖動時,輸出不斷切換的現象。HysteresisMcTrack 的一部分,表示每個軌道都可設定不同的遲滯。

 

McCamSwitch 的範例

參數 型別 開關 01 開關 02 開關 03 開關 04 ... 開關 N
TrackNumber INTEGER 1 1 1 2    
FirstOnPosition [單位] LREAL 2000 2500 4000 3000    
LastOnPosition [單位] LREAL 3000 3000 6000 --    
AxisDirection INTEGER 1=正向 2=負向 0=雙向 0=雙向    
CamSwitchMode INTEGER 0=位置 0=位置 0=位置 1=時間    
Duration LREAL -- -- -- 1.35 秒    

 

McOutput 的範例

參數 MC_OUTPUT[0] MC_OUTPUT[1] MC_OUTPUT[2] - - - MC_OUTPUT[31]
IsAxis FALSE FALSE FALSE - - - FALSE
Index 0 0 0 - - - 0
BitOffset 0 1 2 - - - 31

 

I/O 模組之範例

 

下圖使用了上例 McCamSwitch 的值,不使用 On/OffCompensation Hysteresis,此為當軸持續朝正向移動時的輸出行為。

SetAxisCamSwitch – 正向

 

正向:輸出行為

TrackNumber 1(開關 01, 02, 03)匹配到 McOutput[1];TrackNumber 2(開關 04)匹配到 McOutput[2]。當開關 01開關 02開關 03 被觸發時,第一個 I/O 模組(索引 0)上的第二個輸出(輸出 1)即被開啟。當開關 04 被觸發時,第三個輸出(輸出 2)即被開啟。

 

On/Off 補償之範例

以下範例使用 OnCompensation -125ms 與 OffCompensation +250ms。

 

下圖為當軸持續朝負向移動,且不使用 On/OffCompensation 與 Hysteresis 時的輸出行為。

 

SetAxisCamSwitch – 負向

 

負向:輸出行為

 

EnableMask

EnableMask 是一個含有 32 位元的 uint32 參數,每個位元都是一個 bool 值,可控制輸出。輸出可透過將相應的位元設為 TRUE 或 FALSE 來啟用或停用,例如位元 0 控制 McOutput[0];位元 1 控制 McOutput[1],若位元 0 和位元 1 都設為 TRUE,其輸出即被啟用,意即當相對應的開關被觸發時,其輸出即被開啟。若位元 0 和位元 1 都設為 FALSE,其輸出即被停用,即使相對應的開關被觸發時,其輸出也不會被開啟。

位元 位元 0 位元 1 位元 2 位元 3 - - - - 位元 31
TRUE/FALSE TRUE/FALSE TRUE/FALSE TRUE/FALSE - - - - TRUE/FALSE

 

McOutput 的範例

參數 MC_OUTPUT[0] MC_OUTPUT[1] MC_OUTPUT[2] - - - MC_OUTPUT[31]
IsAxis FALSE FALSE FALSE - - - FALSE
Index 0 0 0 - - - 0
BitOffset 0 1 2 - - - 31

 

EnableMask 位元之範例 1

位元 0、1、2 為 TRUE,意即輸出 0、1、2 被啟用,當相對應的開關被觸發時,輸出即被開啟。

位元 位元 0 位元 1 位元 2 位元 3 - - - - 位元 31
TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE

 

正向:輸出行為

 

EnableMask 位元之範例 2

位元 0、2 為 TRUE,意即輸出 0、2 被啟用,當相對應的開關被觸發時,僅有這 2 個輸出會被開啟。

位元 位元 0 位元 1 位元 2 位元 3 - - - - 位元 31
TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE

 

正向:輸出行為

 

EnableMask 位元之範例 3

所有位元均為 FALSE,意即所有輸出均停用,即使相對應的開關被觸發時,輸出也不會被開啟。

位元 位元 0 位元 1 位元 2 位元 3 - - - - 位元 31

FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

 

正向:輸出行為

 

範例

KsCommandStatus EnableSwitches(INT Index) {
   //Each track will control one output and can contain multiple switches
   /*On compensation is a delay in seconds before the output
     is turned on when a switch becomes active*/
   /*Off compensation is a delay in seconds before the outout
     is turned off when a switch becomes inactive*/
   /*Hysteresis adds a minimum distance in between switches
     to prevent an output from switching on and off*/
   McTrack Tracks[2] = {
      //OnCompensation   OffCompensation   Hysteresis
      {    -0.125,            0.25,            0 },
      {         0,               0,            0 }
      };

   //Defines the output for each track
   //The type selects between axes and modules. TRUE: Axis, FALSE: Module
   //Index of the axis or module
   //Offset of the output bit in the device output buffer
   McOutput Outputs[2] = {
   //Axis        Index       Offset
   { FALSE,        1,          0 },
   { TRUE,       Index,        1 }
   };

   //Defines each switch.
   //Index of the track the switch belongs to.
   //Position at which the switch is enabled.
   //Position at which the switch is disabled for distance switches.
   //Direction in which the switch is triggered. 0: Both, 1: Positive, 2: Negative
   //Switch mode. 0: Distance, 1: Time
   //Duration in seconds the switch stays enabled. For time switches.
   McCamSwitch Switches[4] = {
      //TrackNumber FirstOnPosition LastOnPosition AxisDirection CamSwitchMode Duration
      {     1,            200,            800,            1,            0,         0 },
      {     1,           2500,           3000,            2,            0,         0 },
      {     1,           4000,           6000,            0,            0,         0 },
      {     2,           3000,              0,            0,            1,      1.35 }
      };

   KsCommandStatus camSwitch = SetAxisCamSwitch(
      Index,      //Index
      4,          //SwitchLength
      Switches,   //Switches
      2,          //TrackLength
      Outputs,    //Outputs
      Tracks,     //Tracks
      3,          //EnableMask, enabling track 1 and 2
      mcSetValue  //ValueSource
   );

   return camSwitch;
}

使用需求

  RT Win32
最低支援版本 4.0 4.0
標頭檔 ksmotion.h ksmotion.h
程式庫 KsApi_Rtss.lib KsApi.lib

參見

AbortCommand

PowerAxis

ResetAxis

SetAxisCyclicSwitch

SetGroupPathCamSwitch